<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <!--{include file='comm/header.tpl'}-->
        <!--{include file="comm/icheck.tpl"}-->
        <title>商品评论列表</title>
    </head>
    <body>
        <div class="container">
            <div class="comm_content">
                <div class="search-box">
                    <div style="position:relative">
                        <form class="form-inline" id="search_form" onsubmit="return false;">
                            <table>
                                <tbody>
                                    <tr>
                                        <td>
                                            <span>
                                                处理状态：
                                                <select class="form-control w150" id="comment_status" name="comment_status" size="1" style="width:160px;">
                                                    <option value="">请选择</option>
                                                    <option value="0">未回复</option>
                                                    <option value="1">已回复</option>
                                                </select>
                                            </span>
                                            <span><button type="button" class="btn btn-primary" onclick="source.search();" />查询</button></span>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </form>
                    </div>
                </div>
                <table id="flex" style="display:none"></table>
            </div>
            <div id="pop" style="display: none;">
                <form class="form-horizontal" id="editForm" onsubmit="return false;">
                    <div class="form-group">
                        <label for="cityID" class="col-sm-3 control-label"><span class="red">*</span> 城市：</label>
                        <div class="col-sm-9">
                            <select name="cityID" id="cityID" class="form-control w150" >
                                <!--{foreach from=$city item=c}-->
                                    <!--{if $c.id == 110}-->
                                        <option value="<!--{$c.id}-->" selected><!--{$c.name}--></option>
                                    <!--{else}-->
                                        <option value="<!--{$c.id}-->"><!--{$c.name}--></option>
                                    <!--{/if}-->
                                <!--{/foreach}-->
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="goodsName" class="col-sm-3 control-label"><span class="red">*</span> 商品名称：</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control w300" id="goodsName" name="goodsName" value=""  onblur="source.checkGoods()" placeholder="请输入商品名称">
                        </div>
                    </div>
                    <input type="text" name="twoPostID"   value="" id="twoPostID" style="display: none;">
                    <div class="form-group">
                        <label for="creator" class="col-sm-3 control-label"><span class="red">*</span> 用户名：</label>
                        <div class="col-sm-9">
                            <input type="text"  class="form-control w300"  id="creator" name="creator"  placeholder="请输入用户名(手机号)">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="comment_item" class="col-sm-3 control-label"><span class="red">*</span> 评论项：</label>
                        <div class="col-sm-9" id="comment_item">
                            <div class="fl" style="margin: 0px 10px 10px 0px;">
                                <input type="checkbox" class="square-radio" id="comment_item_1" name="comment_item" value="1">
                                <label for="comment_item_1">非常好吃</label>
                            </div>
                            <div class="fl" style="margin: 0px 10px 10px 0px;">
                                <input type="checkbox" class="square-radio" id="comment_item_2" name="comment_item" value="2">
                                <label for="comment_item_2">配送服务好</label>
                            </div>
                            <div class="fl" style="margin: 0px 10px 10px 0px;">
                                <input type="checkbox" class="square-radio" id="comment_item_3" name="comment_item" value="3">
                                <label for="comment_item_3">口感细腻</label>
                            </div>
                            <div class="fl" style="margin: 0px 10px 10px 0px;">
                                <input type="checkbox" class="square-radio" id="comment_item_4" name="comment_item" value="4">
                                <label for="comment_item_4">清甜可口</label>
                            </div>
                            <div class="fl" style="margin: 0px 10px 10px 0px;">
                                <input type="checkbox" class="square-radio" id="comment_item_5" name="comment_item" value="5">
                                <label for="comment_item_5">蛋糕很漂亮</label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="comment_content" class="col-sm-3 control-label"><span class="red">*</span> 评论内容：</label>
                        <div class="col-sm-9">
                            <textarea id="comment_content" class="form-control w300" placeholder="请输入评论内容" name="comment_content"></textarea>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <script>
            $("#flex").flexigrid({
                url:"/invokingAjax-backend/content/comment.ajax?operFlg=1",
                dataType: "json",
                colModel : [
                    {display: "操作", width : 50, align: 'center'},
                    {display: "商品名称", width : 150 },
                    {display: "评论内容", width : 800},
                    {display: "评论时间", width : 150 },
                    {display: "评论来源", width : 60 },
                    {display: "用户名", width : 100},
                    {display: "回复时间", width : 150},
                    {display: "回复人", width : 80},
                    {display: "处理状态", width : 60}
                ],
                buttons : [
                    {name: "新增", bclass: "add", onpress : "source.addComment"},
                    {separator: true},
                    {name: "批量回复", bclass: "add", onpress : "source.checkAnswer"},
                    {separator: true},
                    {name: "删除", bclass: "delete", onpress : "source.check"},
                    //{separator: true},
                    //{name: "导出评论", bclass: "delete", onpress : "source.checkExport"}
                ],
                sortname: "comment_id",
                sortorder: "desc",
                usepager: true,
                rp: 10,
                useRp: true,
                showTableToggleBtn: true
            });

            var source = {
                pubuuid: '',
                flg:1,
                //单条回复
                answer: function(comment_id){
                    E.open ("/quanliadmin/app/content/comment.pscript?operFlg=2&comment_id=" + comment_id);
                },

                //搜索
                search: function() {
                    var dt = $('#search_form').serializeArray();
                    $("#flex").flexOptions({params: dt}).flexReload();
                },

                //批量回复确认
                checkAnswer: function(){
                    //获取选中的行的行数
                    var selected_count=$('.trSelected',flex).length;
                    if (selected_count==0) {
                        E.alert('请选择要批量回复的评论');
                        return;
                    }else{
                        var uuidArr = new Array();
                        for(var i=0; i<selected_count; i++){
                            var uuidStr = $('.trSelected',flex).eq(i).attr('id');
                            var uuid = uuidStr.substr(3);
                            uuidArr.push(uuid);
                        }
                        pubuuid = uuidArr;

                        //弹出确认层
                        E.confirm('是否批量回复这 ' + $('.trSelected',flex).length + ' 条评论吗?', "source.lotAnswer");
                    }
                },

                //批量回复
                lotAnswer: function(){
                    $.ajax({
                        type: "POST",
                        url:  "/invokingAjax-backend/content/comment.ajax?operFlg=3",
                        data: {'uuidArr' : pubuuid},
                        dataType: "JSON",
                        success: function( result_obj ) {
                            if (result_obj.code == 200) {
                                $("#flex").flexReload();
                                E.alert(result_obj.message,  2);
                            } else {
                                E.alert(result_obj.message);
                            }
                        }
                    });
                },
                //删除确认
                check: function(){
                    //获取选中的行的行数
                    var selected_count=$('.trSelected',flex).length;
                    if (selected_count==0) {
                        E.alert('请选择要删除的评论');
                        return;
                    }else{
                        var uuidArr = new Array();
                        for(var i=0; i<selected_count; i++){
                            var uuidStr = $('.trSelected',flex).eq(i).attr('id');
                            var comment_id = uuidStr.substr(3);
                            uuidArr.push(comment_id);
                        }
                        pubuuid = uuidArr;

                        //弹出确认层
                        E.confirm('是否删除这 ' + $('.trSelected',flex).length + ' 条评论吗?', "source.del");
                    }
                },
                //删除
                del: function(){
                    $.ajax({
                        type: "POST",
                        url:  "/invokingAjax-backend/content/comment.ajax?operFlg=4",
                        data: {'uuidArr' : pubuuid},
                        dataType: "JSON",
                        success: function( result_obj ) {
                            if (result_obj.code == 200) {
                                $("#flex").flexReload();
                                E.alert(result_obj.message,  2);
                            } else {
                                E.alert(result_obj.message);
                            }
                        }
                    });
                },

                //新增评论
                addComment:function(){
                    E.popup.open({
                        id:"pop",   		 //获取id为"pop"元素内的HTML
                        title: "新增评论",       //弹出层标题
                        css: "width:800px;",     //设置弹出层样式
                        btnName: "保存",         //执行“确定”操作的按钮名称
                        btnCall:"source.addCommentCheck();"  //点击确定后执行的方法
                    });
                    $('.square-radio').iCheck({
                        checkboxClass: 'icheckbox_square-blue',
                        radioClass: 'iradio_square-blue',
                        increaseArea: '20%' // optional
                    });
                },

                checkInfo:function( flg ){
                    if( flg == 1){
                        source.checkGoods();
                    }else{
                        source.checkUser();
                    }
                },

                //新增评价检查商品是否存在
                checkGoods:function(){
                    var cityID = $('#cityID').val();
                    var goodsName = $('#goodsName').val();
                    if( goodsName == '' ){
                        E.alert('商品名称必须填写');
                        return;
                    }
                    E.ajax_post({
                        url: '/invokingAjax-backend/content/comment.ajax?operFlg=5',
                        data: {
                            cityID:cityID,
                            goodsName:goodsName
                        },
                        call: function( o ){
                            if( o.code == 200 ){
                                $('#twoPostID').val( o.data.twoPostID );
                            }else{
                                E.alert( o.message );
                                $('#goodsName').val('');
                                return false;
                            }
                        }
                    });
                },


                //新增评价检查用户名是否注册
                checkUser:function(){
                    var userName  = $('#creator').val();
                    if( userName == ''){
                        E.alert('用户名必须填写');
                        return false;
                    }else if( !E.isMobile( userName ) ){
                        E.alert('用户名必须是手机号');
                        $('#creator').val('');
                        return false;
                    }

                    E.ajax_post({
                        url: '/invokingAjax-backend/content/comment.ajax?operFlg=6',
                        data: {userName:userName},
                        call: function( o ){
                            if( o.code == 200 ){
                                E.alert( o.message );
                                $('#creator').val('');
                                return false;
                            }
                        }
                    })
                },

                //保存新增评论
                addCommentCheck:function(){

                    var dt = E.getFormValues('editForm');

                    var error = '';
                    if( dt.cityID == '' ){
                        error += '城市不能为空<br>';
                    }

                    if( dt.goodsName == ''){
                        error += '商品名称不能为空<br>';
                    }else{
                        if( dt.twoPostID == '' ){
                            error += '网购号不能为空<br>';
                        }
                    }

                    if( dt.creator == ''){
                        error += '用户名不能为空<br>';
                    }else{
                        if( !E.isMobile(dt.creator)){
                            error += '用户名必须为手机号<br>';
                        }
                    }

                    if (!dt.comment_item || dt.comment_item.length == 0)
                        error += '请选择评论项<br/>';

                    if( dt.comment_content == ''){
                        error += '评论内容必须填写<br/>';
                    }

                    if( error !=  '' ){
                        E.alert( error );
                        return false;
                    }

                    //保存评论相关信息
                    E.ajax_post({
                        url: '/invokingAjax-backend/content/comment.ajax?operFlg=7',
                        data: dt,
                        call: function( o ){
                            if( o.code == 200 ){
                                E.popup.close();
                                E.alert( o.message,2 ,source.load );
                                return false;
                            }else{
                                E.alert( o.message );
                                return false;
                            }
                        }
                    })

                },

                load: function() {
                    $("#flex").flexReload();
                }
            };
        </script>
    </body>
</html>